<?php
	
	require_once("fta.201003310000/fta.php");
	fta_registerModules(
		array(
		"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
		"site/components/MAIMember",
		"FTAFormMailer/ftaFormMailer",
		"FTAWebPage/ftaDefaultWidgets"
	));	
	
	
	$memberId = extractStringWithKeyFromArray("productId", $_REQUEST, null);
	
	//echo "class = $class";
	if(!is_null($memberId)){
		$o = mai_getSharedMemberObject();
		$member = $o->getMember($memberId);
		$_POST['memberTitle'] = $member->title;
	}
	
	if(isset($_POST['member'])){
		$_POST['member'] = 'true';
	} else {
		$_POST['member'] = 'false';
	}
	
	$authInfo = setupPublicUser();
					
	//ie cluster fuck 
	$submit_x = extractBooleanWithKeyFromArray('join_x',$_POST,false);
	$submit_y = extractBooleanWithKeyFromArray('join_y',$_POST,false);
	$submit = ($submit_x || $submit_y);
	$submit = extractBooleanWithKeyFromArray('join',$_POST,$submit);
	
	$formDescriptor = fta_getFormMailerFormDescriptor(2460,$db);
	
	$formSent = false;
	if ( $submit ) {
		$invalidFields = array();
		
		// validate the form..
			$extractedFormData = fta_formMailerValidateFormData($formDescriptor, $_POST,$invalidFields);
		
		
		
		//$recipients = array();		
		//$formSent = fta_formMailerSendForm($formDescriptor,$_POST,$recipients, $authInfo, $invalidFields, $db );
		//echo "formSent = <pre>";print_r($formSent);echo "</pre>";
		//echo "invalidFields = <pre>";print_r($invalidFields);echo "</pre><br /><br />";

		//$toAddress = extractEmailWithKeyFromArray('email',$_REQUEST ,null);
		/*if ($formSent && !is_null($toAddress) && $formDescriptor->sendThankYouEmail){

			fta_formMailerSendThankYouEmail(
				array(
				$toAddress	
				),$formDescriptor
			);
		}*/	
		
		
		if(count($invalidFields) == 0 ){
		//	header("Location: /Cart/");
		//	echo "Form Sent";
		
		//Save data to session
			$_POST['formMailerId'] = "2460";
			$formMailerDataForOrderItem = serialize($_POST);
			$_POST['formMailerDataForOrderItem'] = $formMailerDataForOrderItem;
			
			//echo "post = <pre>";print_r($_POST);echo "<pre>";
			include_once("../html/cart.php");
			exit();die();
		}
		
			
	}
	
	
	
	
	
	
	
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="Keywords" content="<?php echo $metadataKeywords; ?>" />
<meta name="Description" content="<?php echo $metadataDescription; ?>" />

<title><?php echo $pageTitle; ?> - Classes | Mairangi Arts Centre</title>
<?php include ("includes/external-files.php"); ?>


<script src="/js/jquery.inlined-forms.js" type="text/javascript"></script> 


<?php include ("includes/analytics.php"); ?>   
</head>

<body id="members" class="">



<?php include ("includes/head.php"); ?>





<div id="container">


	<div id="content">
    	

         
        
        <div id="content-blocks">
        <h1><?php echo $pageHeading; ?></h1>
        
        
            <?php echo $pageContent; ?>
            
            
            
            
            
            
           <form id="membership-form" method="post" action="<?= $_SERVER['REQUEST_URI'] ?>" enctype="multipart/form-data" >
		        <input type="hidden" name="returnUrl" value="/Membership/" />
		        <input type="hidden" name="orderStep" value="orderItem" /> 
		        <input type="hidden" name="quantity" value="1" />


		        <h2>Join Online!</h2>
		        
		        <div class="form-left">
				
						<div>
						<label>Join me up as:</label>
						<select name="productId" id="productId" class="memberSelect">
							<?php if(!isset($_POST['productId']) || $_POST['productId'] == '') { $_POST['productId'] = null; } echo mai_getMembersSelect($_POST['productId']); ?>
							<?php //<option value="productDocumentcode">Product Title</option> ?>
						</select>
						<?php echo fta_getFormMailerValidationMessageForField('productId', $invalidFields, $formDescriptor); ?>
						</div>
							
						
						<div>
						<input type="checkbox" <?php echo fta_getFormMailerInputIdAndValue('member',$_REQUEST, $formDescriptor); if($_POST['member'] == "true"){ echo "checked"; } ?> /> <label style="display: inline;" for="member">Are you renewing your membership?</label>
						
						<?php echo fta_getFormMailerValidationMessageForField('member', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('memberNo',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
						<label for="memberNo" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Membership No: (please enter if renewing your membership)</label>
						<input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('memberNo',$_REQUEST, $formDescriptor); ?> />
						<?php echo fta_getFormMailerValidationMessageForField('memberNo', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('firstName',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="firstName" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">First Name:</label>
							<input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('firstName',$_REQUEST, $formDescriptor); ?> />
							<?php echo fta_getFormMailerValidationMessageForField('firstName', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('lastName',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="lastName" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Last Name:</label>
							<input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('lastName',$_REQUEST, $formDescriptor); ?> />
							<?php echo fta_getFormMailerValidationMessageForField('lastName', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="email" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Email:</label>
							<input class="input-text" <?php echo fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('email', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="phone" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Phone:()</label>
							<input class="input-text" <?= fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('phone', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="mobile" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Mobile:()</label>
							<input class="input-text" <?= fta_getFormMailerInputIdAndValue('mobile',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('mobile', $invalidFields, $formDescriptor); ?>
						</div>
						
		        
				</div>
				
				
		        <div class="form-right">
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="street" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Address Line 1:</label>
							<input class="input-text" <?= fta_getFormMailerInputIdAndValue('street',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('street', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="suburb" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Address Line 2:</label>
							<input class="input-text" <?= fta_getFormMailerInputIdAndValue('suburb',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('suburb', $invalidFields, $formDescriptor); ?>
						</div>
						
						<div>
				        <?php 
				        	$inputValue = '';
				        	$inputValues = '';
				        	ob_start();
				        	fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor);
				        	$inputValue = ob_get_clean();
				        	$inputValues = explode(" ", $inputValue);
				        ?>
							<label for="city" class="inlined<?php if (trim($inputValues[2]) != 'value=""') { echo " has-text"; } ?>">Town/City:</label>
							<input class="input-text" <?= fta_getFormMailerInputIdAndValue('city',$_REQUEST, $formDescriptor); ?>/>
							<?= fta_getFormMailerValidationMessageForField('city', $invalidFields, $formDescriptor); ?>
						</div>


		        	<br>
					<label >The Mairangi Arts Centre relies on the input of volunteers. If you can help in any of the following areas please select them:</label>
					<br>

                    <select <?= fta_getFormMailerInputIdAndValue('volunteer',$_REQUEST, $formDescriptor); ?>>
                    	<option <?php if(!isset($_POST['volunteer'])){ echo "selected"; } ?> value="">Please Select:</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Minding Desk'){ echo "selected"; } ?> value="Minding Desk">Minding Desk</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Gallery'){ echo "selected"; } ?>  value="Gallery">Gallery</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Gardening'){ echo "selected"; } ?>  value="Gardening">Gardening</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Working Bees'){ echo "selected"; } ?>  value="Working Bees">Working Bees</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Mail Outs'){ echo "selected"; } ?>  value="Mail Outs">Mail Outs</option>
                    	<option <?php if(isset($_POST['volunteer']) && $_POST['volunteer'] == 'Catering'){ echo "selected"; } ?>  value="Catering">Catering</option>
                    </select>
                    <?= fta_getFormMailerValidationMessageForField('volunteer', $invalidFields, $formDescriptor); ?>
					
					
							        <input id="join" name="join" type="submit" class="button" value='1' />


		        </div>
		        
		        
		        
		        
		        
		        
		        
		        
		        
		        
		    </form>  
			
		    
		    
		    
		    
		    
		    
		    
		    
		</div><!-- Content-blocks ends -->
        
    
    
    
   </div><!-- Content ends -->


    

    
</div><!-- Container ends -->




<?php include ("includes/foot.php"); ?>





</body>

</html>